<?php
class IndexControl extends Control{
	//显示首页
	public function Index(){
		$user=new UserModel();
		$rows=$user->searchUser();
		$this->smarty->assign('rows',$rows);
		$this->smarty->display('index.html');
	}
	//显示添加页面
	public function add(){
		$this->smarty->display('add.html');
	}
	//添加用户
	public function add_ok(){
		$file_name=$_FILES['user_img']['tmp_name'];	
		//拼凑图片的路径及名称
		$dir="includes/images/".uniqid().$_FILES['user_img']['name'];
		//将图片从临时目录移动到服务器真实目录内保存
		move_uploaded_file($file_name,$dir);
		$user=new userModel();
		$user->user_name=$_POST['user_name'];
		$user->user_img=$dir;
		$res=$user->insert();
		if($res){
			header("location:index.php?group=Home&module=Index&act=index");
		}else{
			header("location:index.php?group=Home&module=Index&act=add");
		}
	}
	//用户登录
	public function login(){
		$this->smarty->display('login.html');
	}
	//判断用户
	public function check_login(){
		$user_name=$_POST['user_name'];
		$user=new userModel();
		$user->user_name=$_POST['user_name'];
		$res=$user->check_login();
		if($res){
			$_SESSION['user_id']=$res['user_id'];
			header("location:index.php?group=Home&module=Daka&act=search");
		}else{
			header("location:index.php?group=Home&module=Index&act=login");
		}
	}
	//打卡
	public function daka(){
		$user_id=$_GET['user_id'];
		$daka=new DakaModel();
		$daka->user_id=$user_id;
		$res=$daka->insert();
		if($res){
			header("location:index.php?group=Home&module=Index&act=index");
		}else{
			echo '打卡失败';
		}
	}
}